package top.wineye.spring.dependency.resolve;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import top.wineye.spring.dependency.pojo.Biz;

/**
 * 依赖注入的依赖解析过程
 * {@link org.springframework.beans.factory.support.DefaultListableBeanFactory}
 *
 * <ul>
 *     <li>DefaultListableBeanFactory#resolveDependency</li> 打断点进行观察
 *     <li>DependencyDescriptor</li>
 *     <li>AutowireCandidateResolver</li>
 * </ul>
 *
 */
@Configuration // not necessary, make idea happy
public class DependencyResolve {

    @Autowired
    Biz biz;

    public static void main(String[] args) {
        var ctx = new AnnotationConfigApplicationContext(DependencyResolve.class);

        DependencyResolve bean = ctx.getBean(DependencyResolve.class);
        System.out.println(bean.biz);

        ctx.close();
    }

    @Bean
    @Primary
    public Biz biz1() {
        return creatBiz("1");
    }

    public Biz biz2() {
        return creatBiz("2");
    }

    public static Biz creatBiz(String s) {
        var biz = new Biz();
        biz.setBiz(s);
        return biz;
    }
}
